import { randomUUID } from 'node:crypto';
import { NestFactory } from '@nestjs/core';
import { Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import type { NestExpressApplication } from '@nestjs/platform-express';
import { ExpressAdapter } from '@nestjs/platform-express';
import * as bodyParser from 'body-parser';
import { AppModule } from './modules/app.module';

const logger = new Logger('Bootstrap');

logger.log(randomUUID());

async function bootstrap() {
  // const app = await NestFactory.create(AppModule);
  const app = await NestFactory.create<NestExpressApplication>(
    AppModule,
    new ExpressAdapter(),
    {
      snapshot: true,
    },
  );

  const configService = app.get(ConfigService);

  app.enable('trust proxy');
  app.set('etag', 'strong');

  app.use(
    bodyParser.json({ limit: '10mb' }),
    bodyParser.urlencoded({ limit: '10mb', extended: true }),
  );

  // 设置全局的路由的开始
  const globalPrefix = configService.get('app.prefix', { infer: true });
  app.setGlobalPrefix(globalPrefix);
  logger.error(globalPrefix);
  logger.log(configService);

  // const configService = app.get

  await app.listen(3000);
}
bootstrap();
